package 实现线程.Test02;

public class ThreadTest02 {
    public static void main(String[] args) {
        //创建一个可运行的对象
        MyRunnable r = new MyRunnable();
        //将可运行的对象封装成一个线程对象
        Thread t = new Thread(r);
        //Thread t = new Thread(new MyRunnable());  可合并
        //启动线程
        t.start();
        //采用匿名内部类的方式
        Thread t2 = new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 100; i++){
                    System.out.println("分支线程t2---->" + i);
                }
            }
        });
        t2.start();
        for (int i = 0; i < 100; i++){
            System.out.println("主线程---->" + i);
        }
    }
}
